//index.js
//获取应用实例
const app = getApp();
let utils = require('../../utils/util.js');

Page({
  data: {
    examination_type: [{id:1,title:'教师资格证'},{id:2,title:'教师招聘'}],
    examination_type_active: 1,
    recommend: []
  },
  
  onLoad: function () {
    let _this = this;
    utils.requests({
      url: 'questions/examinationType',
      success:function(data){
        _this.setData({
          examination_type: data.data.data
        })
      }
    });
    _this.setData({
      examination_type_active: wx.getStorageSync('examination_type_active') || 1
    })
    utils.requests({
      url: 'questions/recommend/'+_this.data.examination_type_active,
      success: function(data){
        _this.setData({
          recommend: data.data.data
        });
      }
    });
  },

  //高频考点跳转
  jumpGpkd: function(){
    wx.navigateTo({
      url: '../questions/questions/gpkaodian/gpkaodian',
    })
  },

  // 历年真题跳转
  jumpReally: function(){
    wx.navigateTo({
      url: '../questions/really/really',
    })
  },

  // 考试类型切换
  examinationTypeActive: function(e){
    let _this = this;
    let id = e.currentTarget.id;
    _this.setData({
      examination_type_active: id
    })
    wx.setStorageSync('examination_type_active', id);
    utils.requests({
      url: 'questions/recommend/'+wx.getStorageSync('examination_type_active')||1,
      success: function(data){
        _this.setData({
          recommend: data.data.data
        });
      }
    });
  },

  // 页面跳转
  jump: function(e) {
    let url = e.currentTarget.dataset.url;
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: url+(id>0?'?id='+id:''),
    })
  }

})
